package
{
	import dev.touchswipe.ScreenLock.PinButton;
	import dev.touchswipe.ScreenLock.UnlockWindow;
	import dev.touchswipe.ScreenLock.settingsManager.Settings;
	import dev.touchswipe.ScreenLock.settingsManager.SettingsManager;
	import dev.touchswipe.shared.Fonts;
	
	import flash.desktop.NativeApplication;
	import flash.desktop.NativeProcess;
	import flash.desktop.NativeProcessStartupInfo;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.InvokeEvent;
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;

	public class ScreenLock extends Sprite
	{
		public function ScreenLock()
		{
			NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE,onInvoke);
			NativeApplication.nativeApplication.autoExit=true;
		}
		
		private var _isRunning:Boolean=false;
		
		public function onInvoke(event:InvokeEvent):void{
			for each(var a:String in event.arguments){
				if(a.toLowerCase().charAt(1)=="c")
					new SettingsManager();
				else if(a.toLowerCase().charAt(1)=="p")
					null;
				else if(a.toLowerCase().charAt(1)=="s"&&!_isRunning){
					if(NativeProcess.isSupported){
						var displaySwitch:NativeProcess=new NativeProcess();
						var displaySwitchStartupInfo:NativeProcessStartupInfo=new NativeProcessStartupInfo();
						var exec:File=File.applicationDirectory.resolvePath("TurnOffDisplay.exe");
						displaySwitchStartupInfo.executable=exec;
						displaySwitch.start(displaySwitchStartupInfo);
					}
					_isRunning=true;
					new UnlockWindow();
				}
			}
			stage.nativeWindow.close();
		}
	}
}